﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;
using Medical_Store_Billing.Business_Login_Layer;

namespace Medical_Store_Billing.Report
{
    public partial class FormReport3 : Form
    {
        XuathangBLL m_xuat;
        
        public FormReport3()
        {
            InitializeComponent();
        }

        private void FormReport3_Load(object sender, EventArgs e)
        {

            this.reportViewer1.RefreshReport();
            m_xuat = new XuathangBLL();
            comboBox1.DataSource = m_xuat.laydsxh();
            comboBox1.DisplayMember = "mapx";
            comboBox1.ValueMember = "mapx";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            m_xuat = new XuathangBLL();
            DataTable tb = m_xuat.Timxuathang(comboBox1.SelectedValue.ToString());
            string mapx = comboBox1.SelectedValue.ToString();
            string ngay = tb.Rows[0][1].ToString();
            string makh = tb.Rows[0][2].ToString();
            string manv = tb.Rows[0][4].ToString();
            string nguoilap = textBox2.Text;

            m_xuat = new XuathangBLL();
            
            float sum=0;
            DataTable tb1 = m_xuat.Laychitietxuat1(mapx);
            int j =tb1.Rows.Count;
            for(int i = 0;i<j;i++)
            {
                sum = sum + float.Parse(tb1.Rows[0][3].ToString()) * Int32.Parse(tb1.Rows[0][2].ToString());
                
            }
            string tongtien = String.Format("{0:0,0}", sum) + "  VNĐ";

            IList<ReportParameter> param = new List<ReportParameter>();

            param.Add(new ReportParameter("nguoilap", nguoilap));
            param.Add(new ReportParameter("tongtien", tongtien));
            param.Add(new ReportParameter("manv", manv));
            param.Add(new ReportParameter("makh", makh));
            param.Add(new ReportParameter("ngay", ngay));
            param.Add(new ReportParameter("mapx", mapx));

            reportViewer1.LocalReport.SetParameters(param);

            m_xuat = new XuathangBLL();
            chitietxuathangclassBindingSource.DataSource = m_xuat.Laychitietxuat1(mapx);
            reportViewer1.RefreshReport();
        }
    }
}
